<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            uname: 'zs',
            age: '80'
        }

        const data = {
            num: 80
        }
        // obj.sex = '男'
        // console.log(obj);
        // obj.sex = data.num
        // data.num = 100
        // obj.sex = data.num

        //接收三个参数
        //第一个：对象
        //第二个：对象的属性
        //第三个：配置项(对象)
        // Object.defineProperty(obj, 'sex', {
        //     value: '男',  //属性值
        //     writable: true,  //是否可以修改默认值为false
        //     enumerable: true,  //是否可以被枚举默认值为false
        //     configurable: true, //是否可以被再次修改特性或者删除默认值为false
        // })

        Object.defineProperty(obj, 'sex', {
            get () {
                return data.num
            },
            set (val) {
                data.num = val
            }
        })


        // data.num = 100
        // data.num = 120
        // delete obj.uname
        // delete obj.sex
        // obj.sex = '女'
        // console.log(Object.keys(obj));
        // console.log(obj);
        obj.sex = 120
        console.log(obj.sex);
        // obj.sex = '111'

        

    </script>
</body>

</html>